﻿using AutoMapper;
using ManagementApi.Models.System.Role;
using Modules.Cms;
using Modules.System.Role;
using Modules.System.User;
using PmSoft;

namespace ManagementApi.Models.Cms
{
    public class CmsCustomLeaseDto
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public int CreateUserId { get; set; }

        /// <summary>
        /// 创建人名称
        /// </summary>
        public string CreateUserName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDt { get; set; }

        /// <summary>
        /// 更新人ID
        /// </summary>
        public int UpdateUserId { get; set; }

        /// <summary>
        /// 更新人名称
        /// </summary>
        public string UpdateUserName { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateDt { get; set; }

        /// <summary>
        /// 删除标识
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 客户id
        /// </summary>
        public int CustomId { get; set; }

        /// <summary>
        /// 开始租赁日期
        /// </summary>
        public DateTime StartDt { get; set; }

        /// <summary>
        /// 结束租赁日期
        /// </summary>
        public DateTime EndDt { get; set; }

        /// <summary>
        /// 支付金额
        /// </summary>
        public decimal PayAmount { get; set; }

        /// <summary>
        /// 当前状态;10 租赁中  20 已退租
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 退租日期
        /// </summary>
        public DateTime? ReturnDt { get; set; }

        /// <summary>
        /// 退租金额
        /// </summary>
        public decimal ReturnAmount { get; set; }

        /// <summary>
        /// 退租所属经销商
        /// </summary>
        public int DealerId { get; set; }
        /// <summary>
        /// 送货地址
        /// </summary>
        public string? Address { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        #region 扩展字段
        /// <summary>
        /// 经销商名称
        /// </summary>
        public string DealerName { get; set; }
        /// <summary>
        /// 客户名称
        /// </summary>
        public string CustomName { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        public string Phone {  get; set; }

        /// <summary>
        /// 身份证
        /// </summary>
        public string CardNo { get; set;}
        #endregion
    }

    public static partial class CmsCustomLeaseExceptions
    {
        public static CmsCustomLeaseDto AsDto(this Modules.Cms.Entitys.CmsCustomLease entity)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            var cmsDealerService = ServiceAccessor.GetService<CmsDealerService>();
            var cmsCustomService = ServiceAccessor.GetService<CmsCustomService>();
            CmsCustomLeaseDto dto = new CmsCustomLeaseDto();
            dto.DealerName = cmsDealerService.Get(entity.DealerId??0)?.Name ?? "";
            dto.CustomName = cmsCustomService.Get(entity.CustomId)?.Name ?? "";
            dto.Phone = cmsCustomService.Get(entity.CustomId)?.Phone ?? "";
            dto.CardNo = cmsCustomService.Get(entity.CustomId)?.CardNo ?? "";
            mapper.Map(entity, dto);
            return dto;

        }
    }
}
